/* GUI CONVERTED from poporp6c.p (converter v1.76) Thu Sep  5 11:03:48 2002 */
/* poporp6c.p - PURCHASE ORDER RECEIPTS REPORT Sorted by Packing Slip Nbr*/
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.7.1.20 $                                                */
/*V8:ConvertMode=Report                                                 */
/* REVISION: 7.4     LAST MODIFIED: 12/17/93 BY: dpm            *H074*  */
/* REVISION: 7.4     LAST MODIFIED: 09/27/94 BY: dpm            *FR87*  */
/* REVISION: 8.5     LAST MODIFIED: 11/15/95 BY: taf            *J053*  */
/* REVISION: 8.5     LAST MODIFIED: 02/07/96 BY: *J0CV* Robert Wachowicz*/
/* REVISION: 8.5     LAST MODIFIED: 04/08/96 BY: jzw            *G1LD*  */
/* REVISION: 8.5    LAST MODIFIED: 07/18/96     BY: taf *J0ZS**/
/* REVISION: 8.6     LAST MODIFIED: 10/03/97    BY: mur *K0KK**/
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 06/11/98   BY: *L020* Charles Yen  */
/* REVISION: 9.1      LAST MODIFIED: 06/28/99   BY: *N00Q* Sachin Shinde */
/* REVISION: 9.1      LAST MODIFIED: 12/23/99   BY: *L0N3* Sandeep Rao   */
/* REVISION: 9.1      LAST MODIFIED: 03/06/00   BY: *N05Q* David Morris  */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 09/04/00   BY: *N0RC* Mark Brown       */
/* REVISION: 9.1      LAST MODIFIED: 08/17/00   BY: *N0KM* Rajinder Kamra   */
/* REVISION: 9.1      LAST MODIFIED: 01/18/01   BY: *N0VP* Sandeep P.       */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Old ECO marker removed, but no ECO header exists *K0KK*                    */
/* Revision: 1.7.1.13       BY: Steve Nugent      DATE: 04/17/02  ECO: *P043* */
/* Revision: 1.7.1.14       BY: Patrick Rowan     DATE: 05/24/02  ECO: *P018* */
/* Revision: 1.7.1.15       BY: Hareesh V.        DATE: 06/21/02  ECO: *N1HY* */
/* Revision: 1.7.1.18       BY: Patrick Rowan     DATE: 08/15/02  ECO: *P0FH* */
/* Revision: 1.7.1.19       BY: Karan Motwani     DATE: 08/27/02  ECO: *N1SB* */
/* $Revision: 1.7.1.20 $     BY: Dan Herman       DATE: 08/29/02  ECO: *P0DB*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i }
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define variable mc-error-number like msg_nbr no-undo.
define variable vouchered_qty like pvo_vouchered_qty no-undo.
define variable last_voucher like pvo_last_voucher no-undo.
define variable ers_status like pvo_ers_status no-undo.
define variable ex_rate like prh_ex_rate no-undo.
define variable ex_rate2 like prh_ex_rate2 no-undo.
define variable project like pvo_project no-undo.
define variable l_prh_nbr like prh_nbr no-undo.
define variable l_prh_receiver like prh_receiver no-undo.
define variable RECEIVER as character initial "07" no-undo.
define variable tax_amt as decimal format "->>>>>>>>>>9.99<<<" no-undo.
define variable voucheredTax as decimal no-undo.

{wbrp02.i}

{poporp06.i}       /* INCLUDE ALL SHARED VARIABLES */
{apconsdf.i}
define variable base_std_cost as decimal.
find first gl_ctrl no-lock no-error.
define variable poders as character format "x(2)" no-undo.
define input parameter ers-only as logical no-undo.

for each prh_hist
      where (prh_rcp_date >= rdate and prh_rcp_date <= rdate1
      or  (prh_rcp_date = ? and rdate = low_date))
      and (prh_vend >= vendor and prh_vend <= vendor1)
      and (prh_part >= part and prh_part <= part1)
      and (prh_site >= site and prh_site <= site1)
      and (prh_ps_nbr >= fr_ps_nbr and prh_ps_nbr <= to_ps_nbr)
      and ((prh_type = "" and sel_inv = yes)
      or  (prh_type = "S" and sel_sub = yes)
      or  (prh_type <> "" and prh_type <> "S" and sel_mem = yes))
      and (can-find (first pod_det where
                pod_nbr      = prh_nbr            and
                pod_line     = prh_line           and
                pod_project >= pj and pod_project <= pj1))
      and (uninv_only = no  /* Non-Vouchered Receipts Only = NO */
         or
          (uninv_only   and  /* Non-Vouchered Receipts Only = YES */
            not can-find (first pvo_mstr where
                     pvo_lc_charge         = ""                 and
                     pvo_internal_ref_type = {&TYPE_POReceiver} and
                     pvo_internal_ref      = prh_receiver       and
                     pvo_line              = prh_line           and
                     pvo_last_voucher      <> "")))
      and (base_rpt = "" or base_rpt = prh_curr)
      and (ers-only = no
              or
          (ers-only and
            can-find (first pvo_mstr where
                  pvo_lc_charge         = ""                 and
                  pvo_internal_ref_type = {&TYPE_POReceiver} and
                  pvo_internal_ref      = prh_receiver       and
                  pvo_line              = prh_line           and
                  pvo_ers_status        = 2)))
      use-index prh_rcp_date
   no-lock break by prh_rcp_date by prh_ps_nbr by prh_vend with frame e
      down width 132 no-box:

   /* SET EXTERNAL LABELS */
   setFrameLabels(frame e:handle).

/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/

   assign
      voucheredTax = 0
      tax_amt = 0.

   for each tx2d_det
      where tx2d_ref = prh_receiver
      and  tx2d_nbr = prh_nbr
      and  tx2d_line = prh_line
      and  tx2d_tr_type = "21"
      and not tx2d_tax_in
      and  tx2d_rcpt_tax_point = yes
      no-lock:
      tax_amt = tax_amt + tx2d_cur_tax_amt.
   end. /*for each tx2d_det*/

   for first pvo_mstr
      where pvo_internal_ref_type = {&TYPE_POReceiver}
      and pvo_lc_charge    = ""
      and pvo_internal_ref = prh_receiver
      and pvo_line = prh_line
      no-lock:
      if uninv_only = yes then
         /* Back out the taxes that have been vouchered */
         for each vph_hist where
            vph_pvo_id        = pvo_id  and
            vph_pvod_id_line  = 0       and
            (vph_inv_date >= rdate and
             vph_inv_date <= rdate1) no-lock:

            for each tx2d_det
               where tx2d_ref = vph_ref
               and  tx2d_nbr = prh_receiver
               and  tx2d_line = prh_line
               and  tx2d_tr_type = "22"
               and not tx2d_tax_in
               and  tx2d_rcpt_tax_point = yes
               no-lock:
               voucheredTax = voucheredTax + tx2d_cur_tax_amt.
            end. /*for each tx2d_det*/
      end. /* if uninv_only = yes then */
   end.

   tax_amt = tax_amt - voucheredTax.

   /* DETERMINE THE VALUES FOR ex_rate, ex_rate2, and project. */
   /* THIS IS TO SUPPORT SUPPLIER CONSIGNMENT RECEIPTS, WHERE THE pvo_mstr    */
   /* IS NOT CREATED AT TIME OF RECEIPT BUT TIME OF USAGE.  NORMAL RECEIPTS   */
   /* WILL CREATE pvo_mstr RECORDS WITH THE APPROPRIATE EXCHANGE RATES.       */
   /* FOR SUPPLIER CONSIGNMENT RECIEPTS (WHERE THE pvo_mstr IS NOT AVAILABLE) */
   /* THE EXCHANGE RATES COME FROM THE RECEIPT HISTORY RECORD (prh_hist).     */

   if available (pvo_mstr) then
      assign
         ex_rate  = pvo_ex_rate
         ex_rate2 = pvo_ex_rate2
         project  = pvo_project.
   else
      assign
         ex_rate  = prh_ex_rate
         ex_rate2 = prh_ex_rate2
         project  = "".

   if (oldcurr <> prh_curr) or (oldcurr = "") then do:

      if prh_curr = gl_base_curr then
         rndmthd = gl_rnd_mthd.
      else do:
         /* GET ROUNDING METHOD FROM CURRENCY MASTER */
         {gprunp.i "mcpl" "p" "mc-get-rnd-mthd"
            "(input prh_curr,
              output rndmthd,
              output mc-error-number)"}
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=4}
            if c-application-mode <> "WEB" then
               pause.

            next.
         end.
      end.
      oldcurr = prh_curr.
   end.
   
   do with frame ehead:
      /* SET EXTERNAL LABELS */
      setFrameLabels(frame ehead:handle).
      if first-of (prh_ps_nbr)  or prh_rcp_date <> last_rcp
         or prh_vend <> last_vend then do:
         if first (prh_ps_nbr) or prh_rcp_date <> last_rcp
            or prh_vend <> last_vend then put skip(1).
         else if page-size - line-counter < 7 then do:
            page.
            put skip(1).
         end.

         last_rcp  = prh_rcp_date.
         last_vend = prh_vend .

         display
            prh_rcp_date
            prh_ps_nbr
            prh_vend
         with frame ehead no-box width 132 STREAM-IO /*GUI*/ .
      end.
      if page-size - line-counter < 0 then do:
         page.
         put skip(1).
         display
            prh_rcp_date
            prh_ps_nbr
            prh_vend

            "  " +  dynamic-function('getTermLabelFillCentered' in h-label,
            input "CONTINUE", input 12, input '*') format "x(64)"
            @ descname no-label
         with frame ehead no-box width 132 STREAM-IO /*GUI*/ .
      end.

      /* PRH_PUR_STD IS STORE IN BASE CURRENCY */
      std_cost = prh_pur_std.
      if prh_type = ""
      then
         std_cost = prh_pur_std - prh_ovh_std.
      if use_tot = yes or prh_type = "S"  then std_cost = prh_pur_std.

      /* SAVE THE BASE CURRENCY STANDARD UNIT COST */
      base_std_cost = std_cost.
      /* IF RPT NOT IN BASE, THEN CONVERT THE STD_COST TO DOCUMENT */
      if base_rpt <> ""
         and prh_curr <> base_curr then
      do:

         /* CONVERT FROM BASE TO FOREIGN CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input prh_curr,
              input ex_rate2,
              input ex_rate,
              input std_cost,
              input false, /* DO NOT ROUND */
              output std_cost,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
      end. /* IF BASE_RPT <> "" AND PRH_CURR <> BASE_CURR */

      /* ALWAYS BEGIN WITH THE DOCUMENT CURRENCY UNIT COST */
      base_cost = prh_curr_amt.
      disp_curr = "".

      /* NO NEED FOR CONVERSION BASE_COST = DOC CURR UNIT COST */

      /* IF BASE RPT, SET BASE_COST TO BASE CURR FOR DISPLAY */
      if base_rpt = ""
         and prh_curr <> base_curr then do:
         base_cost = prh_pur_cost.
         disp_curr = getTermLabel("YES",1).
      end.
      
      if uninv_only then
      do:
         /* DETERMINE THE VALUE FOR vouchered_qty */
         {gprun.i ""appvoinv.p""
         "(input """",
           input RECEIVER,
           input prh_receiver,
           input prh_line,
           input prh_ps_nbr,
           output vouchered_qty,
           output last_voucher,
           output ers_status)"}

           qty_open = (prh_rcvd - vouchered_qty) * prh_um_conv.
      end.
      else qty_open = prh_rcvd * prh_um_conv.

      /* CALCULATE THE EXTENDED STANDARD COST FIRST IN BASE */
      std_ext = base_std_cost * qty_open.
      /* ROUND PER BASE CURRENCY ROUND METHOD */

      {gprunp.i "mcpl" "p" "mc-curr-rnd"
         "(input-output std_ext,
           input rndmthd,
           output mc-error-number)"}
      /* CONVERT STD_EXT TO DOCUMENT CURRENCY IF NECESSARY */
      if base_rpt <> ""
         and prh_curr <> base_curr
      then do:

         /* CONVERT FROM BASE TO FOREIGN CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input base_curr,
              input prh_curr,
              input ex_rate2,
              input ex_rate,
              input std_ext,
              input true, /* DO ROUND */
              output std_ext,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
         /* ROUND PER DOCUMENT CURRENCY ROUND METHOD */

      end.

      pur_ext = prh_curr_amt * qty_open.
      /* ROUND PER DOC CURRENCY ROUND METHOD */

      {gprunp.i "mcpl" "p" "mc-curr-rnd"
         "(input-output pur_ext,
           input rndmthd,
           output mc-error-number)"}

      /* CONVERT TO BASE IF NEEDED */
      if base_rpt = ""
         and prh_curr <> base_curr
      then do:

         /* CONVERT FROM FOREIGN TO BASE CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input prh_curr,
              input base_curr,
              input ex_rate,
              input ex_rate2,
              input pur_ext,
              input true, /* DO ROUND */
              output pur_ext,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
         /* ROUND PER BASE CURRENCY ROUND METHOD */

      end.

      {gprunp.i "mcpl" "p" "mc-curr-rnd"
         "(input-output tax_amt,
           input rndmthd,
           output mc-error-number)"}
      /* CONVERT PUR EXT AMT TO BASE IF NECESSARY */
      if base_rpt = ""
         and prh_curr <> base_curr then do:

         /* CONVERT FROM FOREIGN TO BASE CURRENCY */
         {gprunp.i "mcpl" "p" "mc-curr-conv"
            "(input prh_curr,
              input base_curr,
              input ex_rate,
              input ex_rate2,
              input tax_amt,
              input true, /* DO ROUND */
              output tax_amt,
              output mc-error-number)"}.
         if mc-error-number <> 0 then do:
            {pxmsg.i &MSGNUM=mc-error-number &ERRORLEVEL=2}
         end.
         /* ROUND PER BASE CURRENCY ROUND METHOD */
      end.

      std_var = pur_ext - std_ext.
      if prh_type <> "" and prh_type <> "S" then do:
         std_cost = 0.
         std_ext  = 0.
         std_var  = 0.
      end.
      accumulate std_ext (total by prh_ps_nbr).
      accumulate pur_ext (total by prh_ps_nbr).
      accumulate std_var (total by prh_ps_nbr).
      accumulate tax_amt (total by prh_ps_nbr).

      find pod_det where pod_nbr = prh_nbr and pod_line = prh_line no-lock
         no-error.
      if available pod_det then poders = string(pod_ers_opt,">9").

      display
         prh_part                      column-label "Item Number!ERS Option" 
         prh_receiver @ l_prh_receiver column-label "Receiver!Project"
         prh_line
         prh_nbr @ l_prh_nbr           column-label "Order!Ship Date"
         qty_open  format "->>>>>>9.9<<<<<<" column-label "Recd Qty!Ps Qty"
         prh_rcp_type
         std_cost
         disp_curr
         base_cost @ prh_pur_cost format "->>>>>>>>9.99<<<"
         std_ext
         pur_ext  column-label "Ext PO Cost!Ext PO Tax"
         std_var  format "->>>>>>>>>>9.99<<<<"
      with frame e STREAM-IO /*GUI*/ .

      /* FRAME LABEL ASSIGNMENT IS NOT REQUIRED      */

      down with frame e.

      display
         poders @ prh_part
         project @ l_prh_receiver
         prh_ship_date @ l_prh_nbr
         prh_ps_qty @ qty_open

         format "->>>>>>9.9<<<<<<"
      with frame e STREAM-IO /*GUI*/ .

      display tax_amt @ pur_ext with frame e STREAM-IO /*GUI*/ .

      poders = "".

      if last-of (prh_ps_nbr) and show_sub = yes then do:
         if page-size - line-counter < 3 then do:
            page.
            put skip(1).
            display
               prh_rcp_date
               prh_vend
               prh_ps_nbr

               "  " +  dynamic-function('getTermLabelFillCentered' in h-label,
               input "CONTINUE", input 12, input '*') format "x(64)"
               @ descname no-label
            with frame ehead no-box width 132 STREAM-IO /*GUI*/ .
         end.

         underline std_ext pur_ext std_var
         with frame e.

         /* END MOVED AFTER THE END OF IF LAST-OF (prh_ps_nbr) CONDITION */

         display
            (if base_rpt = ""
              then getTermLabelRtColon("BASE_PACKING_SLIP_NUMBER_TOTAL",18)
              else base_rpt + " " + getTermLabelRtColon("PACKING_SLIP_NUMBER_TOTAL",14))
            format "x(18)" to 83 
            accum total by prh_ps_nbr std_ext format "->>>>>>>>>>9.99<<<<" to 99
            accum total by prh_ps_nbr pur_ext format "->>>>>>>>>>9.99<<<<" to 115
            accum total by prh_ps_nbr std_var format "->>>>>>>>>>9.99<<<<" to 131
            accum total by prh_ps_nbr tax_amt format "->>>>>>>>>>9.99<<<<" to 115
            skip(1)
         with frame f width 132 no-labels no-box STREAM-IO /*GUI*/ .
      end.

   end. /* DO WITH */

end.
if page-size - line-counter < 4 then do:
   page.
   put skip(1).
end.
display
   "--------------- --------------- ---------------" to 131
   (if base_rpt = ""

   then getTermLabelRtColon("BASE_REPORT_TOTAL",18)
   else base_rpt + " " + getTermLabelRtColon("REPORT_TOTAL",14))
   format "x(18)"   to 83
   accum total std_ext format "->>>>>>>>>>9.99<<<<"  to 99
   accum total pur_ext format "->>>>>>>>>>9.99<<<<"  to 115
   accum total std_var format "->>>>>>>>>>9.99<<<<"  to 131
   accum total tax_amt format "->>>>>>>>>>9.99<<<<"  to 115
   "=============== =============== ===============" to 131
with frame g width 132 no-labels no-box STREAM-IO /*GUI*/ .

/*V8+*/
